#include "Plane.h"

Plane::Plane(float s, unsigned char *c, float *m)
{
    if (m)
    {
	for (int i = 0; i < 4 * 4; ++i)
	{
	    _m[i] = m[i];
	}
    }
    else
    {
	for (int i = 0; i < 4 * 4; ++i)
	{
	    _m[i] = 0.0;
	}

        _m[0] = 1.0;
        _m[5] = 1.0;
        _m[10] = 1.0;
        _m[15] = 1.0;
    }

    color[0] = c[0];
    color[1] = c[1];
    color[2] = c[2];
    size = s;
}

void Plane::renderInLocalFrame() const
{
    float x1[3] = {_m[12] + size, _m[13] + size, _m[14]};
    float x4[3] = {_m[12] - size, _m[13] - size, _m[14]};
    float x2[3] = {_m[12] - size, _m[13] + size, _m[14]};
    float x3[3] = {_m[12] + size, _m[13] - size, _m[14]};

    glBegin(GL_QUADS);

    glColor3ubv(color);
    glVertex3fv(x1);
    glVertex3fv(x3);
    glVertex3fv(x4);
    glVertex3fv(x2);

    glEnd();
}
